package com.zhengxyou.jetpackdemo.work;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import static com.zhengxyou.jetpackdemo.work.AWorker.KEY_RESULT;
import static com.zhengxyou.jetpackdemo.work.AWorker.KEY_X_ARG;
import static com.zhengxyou.jetpackdemo.work.AWorker.KEY_Y_ARG;
import static com.zhengxyou.jetpackdemo.work.AWorker.KEY_Z_ARG;

public class BWorker extends Worker {

    public BWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        Data inputData = getInputData();

        int anInt = inputData.getInt(KEY_X_ARG, 0);
        String string = inputData.getString(KEY_Y_ARG);
        long aLong = inputData.getLong(KEY_Z_ARG, 0);
        anInt++;
        aLong = aLong * 2;
        string += "===BWork";

        Data data = new Data.Builder()
                .putString(KEY_RESULT, anInt + "," + aLong + "," + string)
                .build();

        return Result.success(data);
    }

}
